import { SEntityInfo } from "../../../../../Message/BroadCast/SEntityInfo";
import { ObjCreate } from "../../common/ObjCreate";
import { ImagesConst } from "../../../resource/ImagesConst";
import { GTextFormat } from "../../../../common/GTextFormat";
import { BuffPanel } from "../../avatar/BuffPanel";
import { ResFileConst } from "../../../resource/ResFileConst";
import { PetExploreToolTip } from "./PetExploreToolTip";
import { BaseProgressBar } from "../../common/BaseProgressBar";
import { PetInfo } from "../../../resource/info/PetInfo";
import { AvatarInfo } from "../../../resource/info/AvatarInfo";
import { SFightAttribute } from "../../../../../Message/Public/SFightAttribute";
import { LoaderManager } from "../../../../../com/gengine/resource/LoaderManager";
import { ImageInfo } from "../../../../../com/gengine/resource/info/ImageInfo";
import { Cache } from "../../../cache/Cache";
import { GLoadedButton } from "../../../../../com/mui/controls/GLoadedButton";
type int = number;
//class PetExploreMainAvatar
    
    export  class PetExploreMainAvatar /* flash.display.Sprite */
    {
        constructor()
        {
            
            this._buffers = [];
            this.init();
            return;
        }

        public get entityInfo(): SEntityInfo
        {
            return this._entityInfo;
        }

        /* internal  */init(): void
        {
            this._bg = ObjCreate.createBg(0, 0, 193, 60, this, ImagesConst.MonsterAvatar);
            this._nameTxt = ObjCreate.createTextField("", 66, 7, 122, 20, this, new GTextFormat("", 12, 16777215));
            this._nameTxt.autoSize = flash.text.TextFieldAutoSize.CENTER;
            this._levelTxt = ObjCreate.createTextField("", 59, 38, 20, 20, this, new GTextFormat("", 12, 16777215));
            this._avatar = new Object /* flash.display.Bitmap */();
            this._avatar.x = 10;
            this._avatar.y = 4;
            this.addChild(this._avatar);
            this._lifeBar = this.createProgressBars("", ImagesConst.MonsterLifeBar, 0, 0);
            this._lifeBar.setSize(122, 10);
            this._lifeBar.setValue(100, 100);
            this._lifeBar.move(66, 27);
            this._lifeBar.showPercentText = false;
            this.addChild(this._lifeBar);
            this._buffPanel = new BuffPanel();
            this._buffPanel.x = 87;
            this._buffPanel.y = 45;
            this.addChild(this._buffPanel);
            this._viewBtn = ObjCreate.createGLoadedButton(ResFileConst.View, 10, 60, 41, 18, this);
            this._viewBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onViewBtnClickHandler);
            this._petToolTip = new PetExploreToolTip();
            this._petToolTip.x = 10;
            this._petToolTip.y = 85;
            this._petToolTip.visible = false;
            this.addChild(this._petToolTip);
            return;
        }

        public setLifePercent(arg1: Boolean): void
        {
            this._lifeBar.showPercentText = arg1;
            return;
        }

        /* internal  */createProgressBars(arg1: string, arg2: string, arg3: int, arg4: int): BaseProgressBar
        {
            var loc1;
            (loc1 = new BaseProgressBar("")).progressBarClass = arg2;
            loc1.setValue(arg3, arg4);
            loc1.setLabelPosition(0, -3);
            return loc1;
        }

        public updateAvatarUI(arg1: SEntityInfo, arg2: Boolean=true): void
        {
            this._entityInfo = arg1;
            if (arg1) 
            {
                this._nameTxt.text = arg1.name;
                this._levelTxt.text = arg1.level.toString();
                this._buffPanel.updateBufferByTSateIdArray(arg1.buffers);
                this._lifeBar.progressBarClass = ImagesConst.MonsterLifeBar;
                if (arg2) 
                {
                    if (this._isShowView) 
                    {
                        this._petToolTip.updateBySEntityInfo(arg1);
                    }
                    this.loadAvatar(PetInfo.getPetAvatarName(arg1.code));
                }
                else 
                {
                    this.loadAvatar(AvatarInfo.getBossAvatarName(arg1.code));
                }
                if (this._isScale) 
                {
                    this._lifeBar.setValue(arg1.life, arg1.maxLife, -1);
                    this._lifeBar.setLabelPosition(-120, -3);
                    this._lifeBar.x = 127;
                }
                else 
                {
                    this._lifeBar.setValue(arg1.life, arg1.maxLife);
                }
            }
            return;
        }

        public showViewBtn(arg1: Boolean): void
        {
            this._isShowView = arg1;
            this._viewBtn.visible = arg1;
            return;
        }

        public updateToolTip(arg1: SFightAttribute): void
        {
            this._petToolTip.updateByFightAttribute(arg1);
            return;
        }

        /* internal  */loadAvatar(arg1: string): void
        {
            if (arg1 != this._backAvatarName) 
            {
                this._avatar.bitmapData = null;
                LoaderManager.instance.load(arg1, this.onAvatarLoaded);
                this._backAvatarName = arg1;
            }
            return;
        }

        /* internal  */onAvatarLoaded(arg1: ImageInfo): void
        {
            this._avatar.bitmapData = arg1.bitmapData;
            return;
        }

        public get isScale(): Boolean
        {
            return this._isScale;
        }

        public set isScale(arg1: Boolean)
        {
            this._isScale = arg1;
            if (arg1) 
            {
                this._bg.scaleX = -1;
                this._bg.x = 193;
                this._bg.y = 0;
                this._nameTxt.x = 0;
                this._nameTxt.y = 7;
                this._nameTxt.width = 122;
                this._nameTxt.autoSize = flash.text.TextFieldAutoSize.CENTER;
                this._levelTxt.x = 118;
                this._levelTxt.y = 38;
                this._avatar.x = 132;
                this._avatar.y = 4;
                this._buffPanel.x = 15;
                this._buffPanel.y = 45;
                this._lifeBar.progressBarClass = ImagesConst.MonsterLifeBarScale;
                this._lifeBar.move(7, 27);
                this._lifeBar.setLabelPosition(0, -3);
                this._viewBtn.x = 150;
                this._petToolTip.x = 25;
                this._petToolTip.y = 80;
            }
            else 
            {
                this._bg.scaleX = 1;
                this._bg.x = 0;
                this._bg.y = 0;
                this._nameTxt.x = 66;
                this._nameTxt.y = 7;
                this._levelTxt.x = 59;
                this._levelTxt.y = 38;
                this._avatar.x = 10;
                this._avatar.y = 4;
                this._lifeBar.move(66, 27);
                this._buffPanel.x = 87;
                this._buffPanel.y = 45;
                this._lifeBar.progressBarClass = ImagesConst.MonsterLifeBar;
                this._viewBtn.x = 10;
                this._petToolTip.x = 10;
                this._petToolTip.y = 85;
            }
            return;
        }

        /* internal  */onViewBtnClickHandler(arg1: Object /* flash.events.Event */): void
        {
            this._petToolTip.visible = !this._petToolTip.visible;
            if (this._petToolTip.visible == true) 
            {
                this._petToolTip.updateByFightAttribute(Cache.instance.petExplore.battlePetFightFightAttribute);
            }
            return;
        }

        /* internal */ /* var */_bg: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_nameTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_levelTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_lifeBar: BaseProgressBar;

        /* internal */ /* var */_avatar: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_buffPanel: BuffPanel;

        /* internal */ /* var */_viewBtn: GLoadedButton;

        /* internal */ /* var */_petToolTip: PetExploreToolTip;

        /* internal */ /* var */_entityInfo: SEntityInfo;

        /* internal */ /* var */_buffers: Array<any>;

        /* internal */ /* var */_backAvatarName: string;

        /* internal */ /* var */_isScale: Boolean;

        /* internal */ /* var */_isShowView: Boolean;
    }
